<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BookController;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

// 健康检查接口
Route::get('/health', function () {
    return response()->json([
        'status' => 'healthy',
        'message' => '服务运行正常',
        'timestamp' => now(),
        'server_time' => date('Y-m-d H:i:s'),
        'php_version' => PHP_VERSION
    ]);
});

// 书籍管理 API 路由
Route::prefix('books')->group(function () {
    // 获取所有书籍列表
    Route::get('/', [BookController::class, 'index']);
    
    // 创建新书籍
    Route::post('/', [BookController::class, 'store']);
    
    // 搜索书籍
    Route::get('/search', [BookController::class, 'search']);
    
    // 获取单个书籍详情
    Route::get('/{id}', [BookController::class, 'show']);
    
    // 更新书籍信息
    Route::put('/{id}', [BookController::class, 'update']);
    
    // 删除书籍
    Route::delete('/{id}', [BookController::class, 'destroy']);
});